<?php
/**
 * @desc:
 * wsxc - ShopGoodsServiceImpl.php
 * @author: quanjianyu
 * @email: 164174421@qq.com
 * @dateTime：2021/4/11 1:22
 */

namespace wsxc\api\impl;

use wsxc\api\IShopGoodsService;
use wsxc\api\IWsxcService;
use wsxc\bean\shopGoods\Goods;
use wsxc\bean\shopGoods\GoodsResult;
use wsxc\bean\shopGoods\LinkedGoods;
use wsxc\bean\shopGoods\LinkedShopGoods;
use wsxc\bean\shopGoods\ShopGoodsListResult;

class ShopGoodsServiceImpl implements IShopGoodsService {
    private IWsxcService $wsxcService;

    /**
     * ShopServiceImpl constructor.
     * @param IWsxcService $wsxcService
     */
    public function __construct(IWsxcService $wsxcService) { $this->wsxcService = $wsxcService; }

    /**
     * @desc: 获取商家商品列表
     * @param string $albumId
     * @param string $searchValue
     * @param string $searchImg
     * @param string $startDate
     * @param string $timestamp 时间戳,毫秒 找上一个items下的最后一个商品中的time_stamp标记传入,就可以拿到下一页的数据
     * @param string $endDate
     * @param string $sourceId
     * @param string $requestDataType
     * @param string $shareType
     * @param array $tagList
     * @return array
     * @author: quanjianyu
     * @email: 164174421@qq.com
     * @dateTime：2021/4/21 19:31
     */
    function getList(string $albumId, string $searchValue = '', string $searchImg = '', string $startDate = '', string $timestamp = '', string $endDate = '', string $sourceId = '', string $requestDataType = '', string $shareType = '', array $tagList = []): array {
        $shopGoods = new LinkedShopGoods($albumId, $searchValue, $searchImg, $startDate, $timestamp, $endDate, $sourceId, $requestDataType, $shareType, $tagList);
        $baseResult = $this->wsxcService->post('/album/personal/all', $shopGoods->toGetParamsArray(), $shopGoods->toPostParamsArray(), ShopGoodsListResult::class);
        return $baseResult->getResult()->getItems();
    }

    /**
     * @desc: 获取商品详情
     * @param string $itemId
     * @param string $targetAlbumId
     * @return Goods
     * @author: quanjianyu
     * @email: 164174421@qq.com
     * @dateTime：2021/4/21 19:48
     */
    public function goodsDetail(string $itemId, string $targetAlbumId = ''): Goods {
        $linkedGoods = new LinkedGoods($itemId, $targetAlbumId);
        $baseResult = $this->wsxcService->get('/commodity/view', $linkedGoods->toGetParams(), GoodsResult::class);
        /**
         * @var $goods Goods
         */
        $goods = $baseResult->getResult()->getCommodity();
        return $goods;
    }

}